Conditions | 1 |
Paths | 1 |
Total Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | var io = require('socket.io').listen(5000); |
||
5 | |||
6 | verboseServer && console.log("ChatServer Started"); //If Verbose Debug |
||
|
|||
7 | io.sockets.on('connection', function (socket) { |
||
8 | verboseServer && console.log("New Connection"); //If Verbose Debug |
||
9 | var userName; |
||
10 | socket.on('connection name',function(user){ |
||
11 | verboseServer && console.log("Connection Name"); //If Verbose Debug |
||
12 | userName = user.name; |
||
13 | clients[user.name] = socket; |
||
14 | io.sockets.emit('new user', user.name + " has joined."); |
||
15 | }); |
||
16 | |||
17 | |||
18 | socket.on('message', function(msg){ |
||
19 | verboseServer && console.log("New msg"); //If Verbose Debug |
||
20 | io.sockets.emit('message', msg); |
||
21 | }); |
||
22 | |||
23 | socket.on('private message', function(msg){ |
||
24 | verboseServer && console.log("New PM"); //If Verbose Debug |
||
25 | fromMsg = {from:userName, txt:msg.txt} |
||
26 | clients[msg.to].emit('private message', fromMsg); |
||
27 | }); |
||
28 | |||
29 | socket.on('disconnect', function(){ |
||
30 | verboseServer && console.log("disconnect"); //If Verbose Debug |
||
31 | delete clients[userName]; |
||
32 | }); |
||
33 | }); |
||
34 |